// Licensed to Elasticsearch B.V under one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information.
//
// ███╗   ██╗ ██████╗ ████████╗██╗ ██████╗███████╗
// ████╗  ██║██╔═══██╗╚══██╔══╝██║██╔════╝██╔════╝
// ██╔██╗ ██║██║   ██║   ██║   ██║██║     █████╗
// ██║╚██╗██║██║   ██║   ██║   ██║██║     ██╔══╝
// ██║ ╚████║╚██████╔╝   ██║   ██║╚██████╗███████╗
// ╚═╝  ╚═══╝ ╚═════╝    ╚═╝   ╚═╝ ╚═════╝╚══════╝
// ------------------------------------------------
//
// This file is automatically generated.
// Please do not edit these files manually.
//
// ------------------------------------------------

#nullable restore

using Elastic.Clients.Elasticsearch.Fluent;
using Elastic.Clients.Elasticsearch.Serialization;
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Text.Json;
using System.Text.Json.Serialization;

namespace Elastic.Clients.Elasticsearch.QueryDsl;

public sealed partial class IntervalsFuzzy
{
	/// <summary>
	/// <para>
	/// Analyzer used to normalize the term.
	/// </para>
	/// </summary>
	[JsonInclude, JsonPropertyName("analyzer")]
	public string? Analyzer { get; set; }

	/// <summary>
	/// <para>
	/// Maximum edit distance allowed for matching.
	/// </para>
	/// </summary>
	[JsonInclude, JsonPropertyName("fuzziness")]
	public Elastic.Clients.Elasticsearch.Fuzziness? Fuzziness { get; set; }

	/// <summary>
	/// <para>
	/// Number of beginning characters left unchanged when creating expansions.
	/// </para>
	/// </summary>
	[JsonInclude, JsonPropertyName("prefix_length")]
	public int? PrefixLength { get; set; }

	/// <summary>
	/// <para>
	/// The term to match.
	/// </para>
	/// </summary>
	[JsonInclude, JsonPropertyName("term")]
	public string Term { get; set; }

	/// <summary>
	/// <para>
	/// Indicates whether edits include transpositions of two adjacent characters (for example, <c>ab</c> to <c>ba</c>).
	/// </para>
	/// </summary>
	[JsonInclude, JsonPropertyName("transpositions")]
	public bool? Transpositions { get; set; }

	/// <summary>
	/// <para>
	/// If specified, match intervals from this field rather than the top-level field.
	/// The <c>term</c> is normalized using the search analyzer from this field, unless <c>analyzer</c> is specified separately.
	/// </para>
	/// </summary>
	[JsonInclude, JsonPropertyName("use_field")]
	public Elastic.Clients.Elasticsearch.Field? UseField { get; set; }

	public static implicit operator Elastic.Clients.Elasticsearch.QueryDsl.Intervals(IntervalsFuzzy intervalsFuzzy) => Elastic.Clients.Elasticsearch.QueryDsl.Intervals.Fuzzy(intervalsFuzzy);
	public static implicit operator Elastic.Clients.Elasticsearch.QueryDsl.IntervalsQuery(IntervalsFuzzy intervalsFuzzy) => Elastic.Clients.Elasticsearch.QueryDsl.IntervalsQuery.Fuzzy(intervalsFuzzy);
}

public sealed partial class IntervalsFuzzyDescriptor<TDocument> : SerializableDescriptor<IntervalsFuzzyDescriptor<TDocument>>
{
	internal IntervalsFuzzyDescriptor(Action<IntervalsFuzzyDescriptor<TDocument>> configure) => configure.Invoke(this);

	public IntervalsFuzzyDescriptor() : base()
	{
	}

	private string? AnalyzerValue { get; set; }
	private Elastic.Clients.Elasticsearch.Fuzziness? FuzzinessValue { get; set; }
	private int? PrefixLengthValue { get; set; }
	private string TermValue { get; set; }
	private bool? TranspositionsValue { get; set; }
	private Elastic.Clients.Elasticsearch.Field? UseFieldValue { get; set; }

	/// <summary>
	/// <para>
	/// Analyzer used to normalize the term.
	/// </para>
	/// </summary>
	public IntervalsFuzzyDescriptor<TDocument> Analyzer(string? analyzer)
	{
		AnalyzerValue = analyzer;
		return Self;
	}

	/// <summary>
	/// <para>
	/// Maximum edit distance allowed for matching.
	/// </para>
	/// </summary>
	public IntervalsFuzzyDescriptor<TDocument> Fuzziness(Elastic.Clients.Elasticsearch.Fuzziness? fuzziness)
	{
		FuzzinessValue = fuzziness;
		return Self;
	}

	/// <summary>
	/// <para>
	/// Number of beginning characters left unchanged when creating expansions.
	/// </para>
	/// </summary>
	public IntervalsFuzzyDescriptor<TDocument> PrefixLength(int? prefixLength)
	{
		PrefixLengthValue = prefixLength;
		return Self;
	}

	/// <summary>
	/// <para>
	/// The term to match.
	/// </para>
	/// </summary>
	public IntervalsFuzzyDescriptor<TDocument> Term(string term)
	{
		TermValue = term;
		return Self;
	}

	/// <summary>
	/// <para>
	/// Indicates whether edits include transpositions of two adjacent characters (for example, <c>ab</c> to <c>ba</c>).
	/// </para>
	/// </summary>
	public IntervalsFuzzyDescriptor<TDocument> Transpositions(bool? transpositions = true)
	{
		TranspositionsValue = transpositions;
		return Self;
	}

	/// <summary>
	/// <para>
	/// If specified, match intervals from this field rather than the top-level field.
	/// The <c>term</c> is normalized using the search analyzer from this field, unless <c>analyzer</c> is specified separately.
	/// </para>
	/// </summary>
	public IntervalsFuzzyDescriptor<TDocument> UseField(Elastic.Clients.Elasticsearch.Field? useField)
	{
		UseFieldValue = useField;
		return Self;
	}

	/// <summary>
	/// <para>
	/// If specified, match intervals from this field rather than the top-level field.
	/// The <c>term</c> is normalized using the search analyzer from this field, unless <c>analyzer</c> is specified separately.
	/// </para>
	/// </summary>
	public IntervalsFuzzyDescriptor<TDocument> UseField<TValue>(Expression<Func<TDocument, TValue>> useField)
	{
		UseFieldValue = useField;
		return Self;
	}

	/// <summary>
	/// <para>
	/// If specified, match intervals from this field rather than the top-level field.
	/// The <c>term</c> is normalized using the search analyzer from this field, unless <c>analyzer</c> is specified separately.
	/// </para>
	/// </summary>
	public IntervalsFuzzyDescriptor<TDocument> UseField(Expression<Func<TDocument, object>> useField)
	{
		UseFieldValue = useField;
		return Self;
	}

	protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings)
	{
		writer.WriteStartObject();
		if (!string.IsNullOrEmpty(AnalyzerValue))
		{
			writer.WritePropertyName("analyzer");
			writer.WriteStringValue(AnalyzerValue);
		}

		if (FuzzinessValue is not null)
		{
			writer.WritePropertyName("fuzziness");
			JsonSerializer.Serialize(writer, FuzzinessValue, options);
		}

		if (PrefixLengthValue.HasValue)
		{
			writer.WritePropertyName("prefix_length");
			writer.WriteNumberValue(PrefixLengthValue.Value);
		}

		writer.WritePropertyName("term");
		writer.WriteStringValue(TermValue);
		if (TranspositionsValue.HasValue)
		{
			writer.WritePropertyName("transpositions");
			writer.WriteBooleanValue(TranspositionsValue.Value);
		}

		if (UseFieldValue is not null)
		{
			writer.WritePropertyName("use_field");
			JsonSerializer.Serialize(writer, UseFieldValue, options);
		}

		writer.WriteEndObject();
	}
}

public sealed partial class IntervalsFuzzyDescriptor : SerializableDescriptor<IntervalsFuzzyDescriptor>
{
	internal IntervalsFuzzyDescriptor(Action<IntervalsFuzzyDescriptor> configure) => configure.Invoke(this);

	public IntervalsFuzzyDescriptor() : base()
	{
	}

	private string? AnalyzerValue { get; set; }
	private Elastic.Clients.Elasticsearch.Fuzziness? FuzzinessValue { get; set; }
	private int? PrefixLengthValue { get; set; }
	private string TermValue { get; set; }
	private bool? TranspositionsValue { get; set; }
	private Elastic.Clients.Elasticsearch.Field? UseFieldValue { get; set; }

	/// <summary>
	/// <para>
	/// Analyzer used to normalize the term.
	/// </para>
	/// </summary>
	public IntervalsFuzzyDescriptor Analyzer(string? analyzer)
	{
		AnalyzerValue = analyzer;
		return Self;
	}

	/// <summary>
	/// <para>
	/// Maximum edit distance allowed for matching.
	/// </para>
	/// </summary>
	public IntervalsFuzzyDescriptor Fuzziness(Elastic.Clients.Elasticsearch.Fuzziness? fuzziness)
	{
		FuzzinessValue = fuzziness;
		return Self;
	}

	/// <summary>
	/// <para>
	/// Number of beginning characters left unchanged when creating expansions.
	/// </para>
	/// </summary>
	public IntervalsFuzzyDescriptor PrefixLength(int? prefixLength)
	{
		PrefixLengthValue = prefixLength;
		return Self;
	}

	/// <summary>
	/// <para>
	/// The term to match.
	/// </para>
	/// </summary>
	public IntervalsFuzzyDescriptor Term(string term)
	{
		TermValue = term;
		return Self;
	}

	/// <summary>
	/// <para>
	/// Indicates whether edits include transpositions of two adjacent characters (for example, <c>ab</c> to <c>ba</c>).
	/// </para>
	/// </summary>
	public IntervalsFuzzyDescriptor Transpositions(bool? transpositions = true)
	{
		TranspositionsValue = transpositions;
		return Self;
	}

	/// <summary>
	/// <para>
	/// If specified, match intervals from this field rather than the top-level field.
	/// The <c>term</c> is normalized using the search analyzer from this field, unless <c>analyzer</c> is specified separately.
	/// </para>
	/// </summary>
	public IntervalsFuzzyDescriptor UseField(Elastic.Clients.Elasticsearch.Field? useField)
	{
		UseFieldValue = useField;
		return Self;
	}

	/// <summary>
	/// <para>
	/// If specified, match intervals from this field rather than the top-level field.
	/// The <c>term</c> is normalized using the search analyzer from this field, unless <c>analyzer</c> is specified separately.
	/// </para>
	/// </summary>
	public IntervalsFuzzyDescriptor UseField<TDocument, TValue>(Expression<Func<TDocument, TValue>> useField)
	{
		UseFieldValue = useField;
		return Self;
	}

	/// <summary>
	/// <para>
	/// If specified, match intervals from this field rather than the top-level field.
	/// The <c>term</c> is normalized using the search analyzer from this field, unless <c>analyzer</c> is specified separately.
	/// </para>
	/// </summary>
	public IntervalsFuzzyDescriptor UseField<TDocument>(Expression<Func<TDocument, object>> useField)
	{
		UseFieldValue = useField;
		return Self;
	}

	protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings)
	{
		writer.WriteStartObject();
		if (!string.IsNullOrEmpty(AnalyzerValue))
		{
			writer.WritePropertyName("analyzer");
			writer.WriteStringValue(AnalyzerValue);
		}

		if (FuzzinessValue is not null)
		{
			writer.WritePropertyName("fuzziness");
			JsonSerializer.Serialize(writer, FuzzinessValue, options);
		}

		if (PrefixLengthValue.HasValue)
		{
			writer.WritePropertyName("prefix_length");
			writer.WriteNumberValue(PrefixLengthValue.Value);
		}

		writer.WritePropertyName("term");
		writer.WriteStringValue(TermValue);
		if (TranspositionsValue.HasValue)
		{
			writer.WritePropertyName("transpositions");
			writer.WriteBooleanValue(TranspositionsValue.Value);
		}

		if (UseFieldValue is not null)
		{
			writer.WritePropertyName("use_field");
			JsonSerializer.Serialize(writer, UseFieldValue, options);
		}

		writer.WriteEndObject();
	}
}